﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Neptuno.Component;
using Neptuno.Model;
using System;

namespace Neptuno.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class RecaladasService
    {
        ViajesComponent Component = new ViajesComponent();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Recalada"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Recaladas AgregarRecalada(Recaladas Recalada)
        {
            return Component.AgregarRecalada(Recalada);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Recalada"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "RecaladaPuerto", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool AgregarRecaladaPuerto(RecaladasPuertos Recalada)
        {
            return Component.AgregarRecaladaPuerto(Recalada);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Recalada"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "RegistroRecalada", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool AgregarRegistroRecalada(RegistrosRecaladas Recalada)
        {
            return Component.AgregarRegistroRecalada(Recalada);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Archivo"></param>
        /// <returns></returns>
        [WebInvoke(UriTemplate = "Archivo", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool AgregarArchivo(Archivos Archivo)
        {
            return Component.AgregarArchivo(Archivo);
        }

        [WebGet(UriTemplate = "ByLinea/{id}", ResponseFormat = WebMessageFormat.Json)]
        public List<Recaladas> ListarByLinea(string id)
        {
            return Component.Listar(int.Parse(id));
        }

        //Warning
        [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json)]
        public List<Recaladas> Listar()
        {
            return Component.Listar();
        }

        [WebGet(UriTemplate = "ByEstado/{id}/{estado}", ResponseFormat = WebMessageFormat.Json)]
        public List<Recaladas> ListarByEstado(string id, string estado)
        {
            return Component.ListarByEstado(int.Parse(id), idAgencia: int.Parse(id));
        }

        [WebGet(UriTemplate = "ByAgencia/{id}", ResponseFormat = WebMessageFormat.Json)]
        public List<Recaladas> ListarByAgencia(string id)
        {
            return Component.Listar(int.Parse(id));
        }

        [WebGet(UriTemplate = "RecaladaPuerto/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public RecaladasPuertos GetRecaladaPuerto(string id)
        {
            return Component.GetRecaladaPuerto(int.Parse(id));
        }

        [WebGet(UriTemplate = "Archivo/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Archivos> GetArchivo(string id)
        {
            return Component.GetArchivos(int.Parse(id));
        }

        [WebGet(UriTemplate = "RegistroRecalada/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<RegistrosRecaladas> GetRegistroRecalada(string id)
        {
            return Component.GetRegistrosRecaladas(int.Parse(id));
        }

        [WebGet(UriTemplate = "Recalada/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Recaladas GetById(string id)
        {
            return Component.GetById(int.Parse(id));
        }

        [WebInvoke(UriTemplate = "", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Actualizar(Recaladas Recalada)
        {
            return Component.Actualizar(Recalada);
        }

        [WebInvoke(UriTemplate = "RegistroRecalada", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool ActualizarRegistroRecalada(RegistrosRecaladas Recalada)
        {
            return Component.ActualizarRegistroRecalada(Recalada);
        }

        [WebInvoke(UriTemplate = "RecaladaPuerto", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool ActualizarRecaladaPuerto(RecaladasPuertos Recalada)
        {
            return Component.ActualizarRecaladaPuerto(Recalada);
        }

        [WebInvoke(UriTemplate = "Viajes", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Viajes AgregarViaje(Viajes viaje)
        {
            var Viaje = Component.AgregarViaje(viaje);
            return Viaje;
        }

        [WebInvoke(UriTemplate = "ByEta", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public List<Recaladas> ListarPorEta(DateTime RangoInicial, DateTime RangoFinal, int idAgencia)
        {
            return Component.ListarByEta(RangoInicial, RangoFinal, idAgencia);
        }

        [WebInvoke(UriTemplate = "Viajes", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool ActualizarViaje(Viajes viaje)
        {
            return Component.ActualizarViaje(viaje);
        }

        [WebGet(UriTemplate = "Viajes/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Viajes GetViaje(string id)
        {
            int idViaje = int.Parse(id);
            return Component.GetViaje(idViaje);
        }
    }
}